home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Presentations / Presentations ’92 / PatchWorks Kit / <PatchWorks++> / GenericPatch.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-15  |  1.9 KB  |  72 lines  |  [TEXT/KAHL]

  1. /*
  2.     GenericPatch.h
  3.     
  4.     Object representing a trap patch. Derived version.
  5.     
  6.     Two interfaces are possible:  you can override Behavior and can access the patch's
  7.     parameters from the parameters[] array provided in the PatchFrame structure; or you
  8.     can override GetBehaviour to call a static member function directly and pull your
  9.     object's instance from the PatchFrame structure, and make your calling conventions
  10.     reflect the actual stack layout.
  11.     
  12.     by Patrick Beard & Mouse Herrel.
  13.     
  14.     ©1991, 92 by Berkeley Systems, Inc. All rights reserved.
  15.  */
  16.  
  17. #pragma once
  18.  
  19. #ifdef applec
  20. #include "Patch.h"
  21. #define AncestorPatch TrapPatch
  22. #endif
  23.  
  24. #ifdef THINK_C
  25. #if __option(a4_globals)
  26. #include "Patch.h"
  27. #define AncestorPatch TrapPatch
  28. #else
  29. #include "TestExtension.h"
  30. #include "ScalperPatch.h"
  31. #define AncestorPatch ScalperPatch
  32. #endif
  33. #endif
  34.  
  35. class GenericPatch : public AncestorPatch {
  36. public:
  37.     void InitGenericPatch(short trap, long resultOffset);
  38.  
  39. protected:
  40.     virtual void Behavior(void);                // override this to do your stuff, or
  41.     virtual PatchProcPtr GetDispatcher(void);    // provide address of routine to call.
  42.     
  43.     // utility functions.
  44.     virtual void AbortTrap(void);                // call to abort the trap.
  45.     
  46. private:
  47.     static void Dispatch(PatchFrame frame);
  48.  
  49. protected:
  50.     PatchFrame* itsFrame;                        // current stack frame.
  51.     long itsResultOffset;                        // offset to the result value on stack.
  52. };
  53.  
  54. class GenericVectorPatch : public VectorPatch {
  55. public:
  56.     void InitGenericVectorPatch(PatchVectorPtr vector, long resultOffset);
  57.  
  58. protected:
  59.     virtual void Behavior(void);                // override this to do your stuff, or
  60.     virtual PatchProcPtr GetDispatcher(void);    // provide address of routine to call.
  61.     
  62.     // utility functions.
  63.     virtual void AbortVector(void);                // call to abort the vector.
  64.     
  65. private:
  66.     static void Dispatch(PatchFrame frame);
  67.  
  68. protected:
  69.     PatchFrame* itsFrame;                        // current stack frame.
  70.     long itsResultOffset;                        // offset to the result value on stack.
  71. };
  72.